<?php

namespace App\Http\Controllers\Admin;

use App\Http\Requests\Video\StoreVideoRequest;
use App\Http\Requests\Video\UpdateVideoRequest;
use App\Model\Video;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests;
use Symfony\Component\HttpFoundation\Request as Req;
use App\Model\VideoCategory as Category;
use App\Model\VideoUrl;
use JWTAuth;
use PHPHtmlParser\Dom;
use DB;

class VideoController extends Controller
{
    public function __construct()
    {
        parent::__construct();
        view()->share([
            '_xHotel' => 'am-in',
            '_menu' => 'am-active',
        ]);

    }


    //添加本地视频
    public function add_local()
    {
        //$ckfinder = $this->getJson("http://".$_SERVER['HTTP_HOST']."/assets/xSystem/vendor/ckfinder/core/connector/php/connector.php?command=GetFiles&lang=zh-cn&type=Upload&currentFolder=%2F电视剧%2F青云志%2F&hash=133a6e01cb2fe87a");
        //return $ckfinder;
        Video::add_local_upload();
        $this->attributes();
        $data = array();
        return view('Admin.xHotel.video.add_local')->with(['_video_add_local' => 'am-active', '_menu' => ''])->with('data', $data);
    }

    public function get_Local_url(Request $request)
    {

        $ckfinder = $this->getJson("http://" . $_SERVER['HTTP_HOST'] . "/assets/xSystem/vendor/ckfinder/core/connector/php/connector.php?command=GetFiles&lang=zh-cn&type=%E8%A7%86%E9%A2%91%E5%88%86%E7%B1%BB&currentFolder=%2F电视剧%2F".$request->name."%2F");
        $datas = json_decode($ckfinder, 1);

        foreach ($datas['files'] as $v) {
            $data[] = "/finder/upload" . $datas['currentFolder']['path'] . $v['name'];
        }

        $this->attributes();
        if (!empty($data)) {
           return response()->json($data);
        }else{
           $datas=array();
           return response()->json($datas);
        }
    }

    /**
     * @param Request $request
     * @return mixed
     */
    public function index(Request $request)
    {
        //return Category::filter_categories();

        $where = function ($query) use ($request) {
            if ($request->has('name') and $request->name != '') {
                $search = "%" . $request->name . "%";
                $query->where('name', 'like', $search);
            }

            if ($request->has('video_category_id') and $request->video_category_id != '-1') {
                $query->where('video_category_id', $request->video_category_id);
            }
            
            if ($request->has('is_show') and $request->is_show != '-1') {
                $query->where('is_show', $request->is_show);
            }

            if ($request->has('is_recommend')) {
                $query->where('is_recommend', true);
            }

            if ($request->has('is_hot')) {
                $query->where('is_hot', true);
            }
            if ($request->has('is_local')) {
                $query->where('is_local', true);
            }

            if ($request->has('is_top')) {
                $query->where('is_top', true);
            }

            if ($request->has('is_new')) {
                $query->where('is_new', true);
            }
        };
        $videos = Video::with(['video_category'])->where($where)
            ->orderBy('is_top', "desc")
            ->orderBy('is_show', "desc")
            ->orderBy('is_hot', "desc")
            ->orderBy('is_new', "desc")
            ->orderBy('is_recommend', "desc")
            ->orderBy('created_at')
            ->paginate(config('xSystem.page_size'));
        $this->attributes();
        //return $videos;
        return view('Admin.xHotel.video.index')->with('videos', $videos);
    }

    /**
     * @return mixed
     *
     */
    public function create()
    {
        $this->attributes();
        return view('Admin.xHotel.video.create')->with(['_video_create' => 'am-active', '_menu' => '']);
    }


    /**
     * 新增
     * @param StoreVideoRequest $request
     * $request
     */
    public function store(StoreVideoRequest $request)
    {

        $map = explode("\n", $request->urls);
        if (empty($map[count($map) - 1])) {
            unset($map[count($map) - 1]);
        }

        if (empty($map[count($map) - 1])) {
            return back()->with('error', '最后回车后地址不能为空');
        };

        foreach ($map as $url) {
            if ($url == "\r") {
                return back()->with('error', '回车后地址不能为空');
            }
            if(!$request->has('is_local')){
                if (!$this->CheckUrl($url)) {
                    return back()->with('error', '视频地址必须以http://或https://开头');
                };
            }
        }

        $data = $request->except(['urls', 'genre']);
        $data['genre'] = trim($request->genre);
        $video = Video::create($data);

        if ($request->has('urls')) {
            foreach ($map as $url) {
                $video->video_url()->create(['url' => $url]);
            }
        }

        Category::clear();
        return redirect('/video')->with('success', '添加成功');

    }

    private function CheckUrl($str)
    {
        if (preg_match("/^(http:\/\/|https:\/\/).*$/", $str)) {
            return true;
        }
        return false;
    }

    private function youku_url($str)
    {
        if (preg_match("/^https?:\/\/[^.]+\.youku\.com\//", $str)) {
            return true;
        }
        return false;
    }

    private function attributes()
    {
        view()->share([
            'categories' => Category::get_categories(),
            'filter_categories' => Category::filter_categories()
        ]);

    }

    /**
     * 修改显示页
     * @param $id
     */
    public function edit($id)
    {

        $video = Video::with('video_url')
            ->find($id);
        $this->attributes();


        Category::clear();
        return view('Admin.xHotel.video.edit')->with('video', $video);
    }

    /**
     * 修改
     * @param UpdateVideoRequest $request
     * @param $id
     */
    public function update(UpdateVideoRequest $request, $id)
    {

        $map = explode("\n", $request->urls);

        if (empty($map[count($map) - 1])) {
            unset($map[count($map) - 1]);
        }

        if (empty($map[count($map) - 1])) {

            return back()->with('error', '最后回车后地址不能为空');
        };

        foreach ($map as $url) {

            if ($url == "\r") {
                return back()->with('error', '回车后地址不能为空');
            }
            if(!$request->has('local')){
                if (!$this->CheckUrl($url)) {
                    return back()->with('error', '视频地址必须以http://或https://开头');
                };
            }
        }

        $data = $request->except(['urls', 'genre']);
        $data['genre'] = trim($request->genre);
        $video = Video::find($id);
        $video->update($data);

        if ($request->has('urls')) {
            VideoUrl::where('video_id', $id)->delete();
            foreach ($map as $url) {
                $video->video_url()->create(['url' => $url]);

            }
        }
        Category::clear();
        return redirect('/video')->with('success', '修改成功');

    }

    /**
     * 删除
     * @param $id
     */
    public function destroy($id)
    {
        if (!Video::check_children($id)) {
            VideoUrl::where('video_id', $id)->delete();
        };
        Video::destroy($id);
        Category::clear();
        return redirect('/video')->with('error', '删除成功');

    }

    /**
     *是否
     * @param Request $request
     */
    public function is_something(Request $request)
    {

        $attr = $request->attr;
        $video = Video::find($request->id);
        $value = $video->$attr ? false : true;
        $video->$attr = $value;
        Category::clear();
        $video->save();
    }

    /**
     *
     * @param Request $request
     * @return array
     */
    public function destroy_checked(Request $request)
    {

        $checked_id = $request->input("checked_id");

        if (!Video::destroy_checked_children($checked_id[0])) {
            VideoUrl::whereIn('video_id', $checked_id)->delete();
        };

        Video::destroy($checked_id);

    }


    public function test()
    {
        Video::destroy(45);
    }


    /**
     * curl获取json
     * @param $url
     * @return mixed
     */
    private function getJson($url)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_ENCODING, "gzip");
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        return curl_exec($ch);
    }

    public function youku_video_list(Request $request)
    {
        //return $request->all();

        if ($request->has('name') and $request->name != '') {

            if ($request->has('video_category_id')) {
                $video = Category::where('id', $request->video_category_id)->select('name')->first();
            }
            $by_keyword = $this->getJson("https://openapi.youku.com/v2/searches/show/by_keyword.json?client_id=32a76d168c65beff&page=1&count=10&keyword=" . $request->name . "&category=" . $video->name . "");
            //return $by_keyword;
            $datas = json_decode($by_keyword, 1);

            $arr = array();
            foreach ($datas['shows'] as $k => $v) {
                if ($v['paid'] == 1) {
                    continue;
                }
                $arr[] = $v;
            }

            $this->attributes();

            return view('Admin.xHotel.video.youku_video')->with(['_video_add' => 'am-active', '_menu' => ''])->with('datas', $arr);
        }
        $this->attributes();

        return view('Admin.xHotel.video.youku_video')->with(['_video_add' => 'am-active', '_menu' => ''])->with('video_datas', $this->video_list());

    }

    public function checked_video(Request $request)
    {
        //return $request->all();

        $result = array();

        //判断视频存不存在
        $isvideo = Video::where('youku_video_id', $request->id)->first();
        if ($isvideo) {
            $result['status'] = 0;
            $result['info'] = '该视频已存在';
            return $result;
        }
        if (!$request->link) {
            $result['status'] = 0;
            $result['info'] = '该视频已下架';
            return $result;
        }

        if ($request->showcategory == "电视剧") {
            if ($this->create_video($request->link) == '') {
                $result['status'] = 0;
                $result['info'] = '由于网络原因请重新添加';
                return $result;
            }
        }

        $data = $request->except(['link', 'category_id', 'showcategory']);
        $data['video_category_id'] = $request->category_id;
        if ($request->showcategory == "综艺") {
            $data['genre'] = "搞笑,真人秀";
        }
        $data['published'] = trim($request->published);
        $data['desc'] = trim($request->desc);
        $data['title'] = $request->name;
        $data['youku_video_id'] = $request->id;
        $video = Video::create($data);
        if ($request->has('link')) {
            if ($request->showcategory == "电影" || $request->showcategory == "综艺") {
                $video->video_url()->create(['url' => $request->link]);
            }
            if ($request->showcategory == "电视剧") {
                $url_link = $this->create_video($request->link);
                foreach ($url_link as $link) {
                    $video->video_url()->create(['url' => "http://v.youku.com/v_show/id_" . $link . "==.html"]);
                }
            }
        }
        $result['status'] = 0;
        $result['info'] = '添加成功';
        return $result;
    }

    /**
     *正则匹配网页
     * @param $test
     * @return mixed
     */
    private function pregURL($test)
    {
        $rule = '/<div\s+[^>]+?name="tvlist"[^>]+?\s+id="item_([^"]+)"\s+title="第\d+集">/';//匹配网页正则
        preg_match_all($rule, $test, $result);
        return $result;
    }

    /**
     * 自动更新电视剧
     */
    public function is_episode()
    {
        $videos = Video::where('is_episode', 1)->where('video_category_id', 1)->get();
        if ($videos) {
            $by_keyword = $this->getJson("https://openapi.youku.com/v2/searches/show/top_unite.json?client_id=32a76d168c65beff&category=电视剧&genre=0&area=0&count=100&page=1&headnum=1&tailnum=1");
            $datas = json_decode($by_keyword, 1);
            $arr = array();
            foreach ($datas['data'] as $k => $v) {
                foreach ($videos as $k2 => $value) {
                    if ($v['programmeId'] == $value->programmeId) {
                        $arr[] = $v;
                        $arr[$k2]['id'] = $value['id'];
                    }
                }
            }
            $ann = array();
            foreach ($arr as $k => $v) {
                $ann[$k]['id'] = $v['id'];
                $ann[$k]['name'] = $v['name'];
                $ann[$k]['programmeId'] = $v['programmeId'];
                $ann[$k]['genre'] = implode(',', $v['genre']);
                $ann[$k]['performer'] = implode(',', $v['performer']);
                $ann[$k]['vpic'] = $v['vpic'];
                $ann[$k]['brief'] = $v['brief'];
                $ann[$k]['subtitle'] = $v['subtitle'];
                $ann[$k]['releaseDate'] = $v['releaseDate'];
                $ann[$k]['programmeSite'] = $v['programmeSite'][0]['episode'][0]['url'];
            }
            $attr = array();
            foreach ($ann as $k => $v) {
                $data['video_category_id'] = 1;
                $data['is_episode'] = 1;
                $data['is_top'] = 1;
                $data['published'] = trim($v['releaseDate']);
                $data['desc'] = trim($v['brief']);
                $data['programmeId'] = $v['programmeId'];
                $data['stars'] = $v['performer'];
                $data['genre'] = $v['genre'];
                $data['title'] = $v['subtitle'];
                $data['name'] = $v['name'];
                $data['thumb'] = $v['vpic'];
                $attr[$k]['data'] = $this->create_video($v['programmeSite']);

                if (empty($attr[$k]['data'])) {
                    $attr[$k]['data'] = $this->create_video($v['programmeSite']);
                }

                $video = Video::find($v['id']);

                $video->update($data);
                if (!empty($attr[$k]['data'])) {
                    VideoUrl::find($v['id'])->where('video_id', $v['id'])->delete();
                    foreach ($attr[$k]['data'] as $link) {
                        $video->video_url()->create(['url' => "http://v.youku.com/v_show/id_" . $link . "==.html"]);
                    }
                }
            }
        }

    }

    //电视剧
    public function onekey_video()
    {
        for ($i = 1; $i <= 4; $i++) {
            $by_keyword = $this->getJson("https://openapi.youku.com/v2/searches/show/top_unite.json?client_id=32a76d168c65beff&category=电视剧&genre=0&area=0&count=100&page=" . $i . "&headnum=1&tailnum=1");
            $datas = json_decode($by_keyword, 1);
            $arr = array();
            foreach ($datas['data'] as $k => $v) {
                if ($v['paid'] == 1) {
                    continue;
                }
                if (!$this->youku_url($v['programmeSite'][0]['episode'][0]['url'])) {
                    continue;
                }
                $arr[] = $v;
            }

            $ann = array();
            foreach ($arr as $k => $v) {
                $ann[$k]['name'] = $v['name'];
                $ann[$k]['programmeId'] = $v['programmeId'];
                $ann[$k]['genre'] = implode(',', $v['genre']);
                $ann[$k]['performer'] = implode(',', $v['performer']);
                $ann[$k]['vpic'] = $v['vpic'];
                $ann[$k]['brief'] = $v['brief'];
                $ann[$k]['subtitle'] = $v['subtitle'];
                $ann[$k]['releaseDate'] = $v['releaseDate'];
                $ann[$k]['programmeSite'] = $v['programmeSite'][0]['episode'][0]['url'];
            }
            foreach ($ann as $k => $v) {
                $isvideo = Video::where('programmeId', $v['programmeId'])->first();
                if ($isvideo) {
                    continue;
                };
                $data['video_category_id'] = 1;
                $data['published'] = trim($v['releaseDate']);
                $data['desc'] = trim($v['brief']);
                $data['programmeId'] = $v['programmeId'];
                $data['stars'] = $v['performer'];
                $data['genre'] = $v['genre'];
                $data['title'] = $v['subtitle'];
                $data['name'] = $v['name'];
                $data['thumb'] = $v['vpic'];
                $ann[$k]['data'] = $this->create_video($v['programmeSite']);
                if (empty($ann[$k]['data'])) {
                    continue;
                }
                $video = Video::create($data);
                foreach ($ann[$k]['data'] as $link) {
                    $video->video_url()->create(['url' => "http://v.youku.com/v_show/id_" . $link . "==.html"]);
                }
            }

            $this->attributes();
            return view('Admin.xHotel.video.youku_video')->with(['_video_add' => 'am-active', '_menu' => ''])->with('video_datas', $this->video_list());
        }
    }

    //电影
    public function add_movie()
    {
        for ($i = 1; $i <= 10; $i++) {
            $by_keyword = $this->getJson("https://openapi.youku.com/v2/searches/show/top_unite.json?client_id=32a76d168c65beff&category=电影&genre=0&area=0&count=100&page=" . $i . "&headnum=1&tailnum=1");
            $datas = json_decode($by_keyword, 1);
            //return $datas;
            $arr = array();
            foreach ($datas['data'] as $k => $v) {
                if ($v['paid'] == 1) {
                    continue;
                }
                if (!$this->youku_url($v['programmeSite'][0]['episode'][0]['url'])) {
                    continue;
                }
                $arr[] = $v;
            }

            $ann = array();
            foreach ($arr as $k => $v) {
                $ann[$k]['name'] = $v['name'];
                $ann[$k]['programmeId'] = $v['programmeId'];
                $ann[$k]['genre'] = implode(',', $v['genre']);
                $ann[$k]['performer'] = implode(',', $v['performer']);
                $ann[$k]['vpic'] = $v['vpic'];
                $ann[$k]['brief'] = $v['brief'];
                $ann[$k]['subtitle'] = $v['subtitle'];
                $ann[$k]['releaseDate'] = $v['releaseDate'];
                $ann[$k]['programmeSite'] = $v['programmeSite'][0]['episode'][0]['url'];
            }
            //return $ann;
            $data = array();
            foreach ($ann as $k => $v) {
                $isvideo = Video::where('programmeId', $v['programmeId'])->first();
                if ($isvideo) {
                    continue;
                };
                $data['video_category_id'] = 2;
                $data['published'] = trim($v['releaseDate']);
                $data['desc'] = trim($v['brief']);
                $data['programmeId'] = $v['programmeId'];
                $data['stars'] = $v['performer'];
                $data['genre'] = $v['genre'];
                $data['title'] = $v['subtitle'];
                $data['name'] = $v['name'];
                $data['thumb'] = $v['vpic'];
                //$data['data'] = $v['programmeSite'];
                $video = Video::create($data);
                $video->video_url()->create(['url' => $v['programmeSite']]);
            }

        }
        $this->attributes();
        return view('Admin.xHotel.video.youku_video')->with(['_video_add' => 'am-active', '_menu' => ''])->with('video_datas', $this->video_list());

    }

    //综艺
    public function add_variety()
    {
        for ($i = 1; $i <= 2; $i++) {
            $by_keyword = $this->getJson("https://openapi.youku.com/v2/searches/show/top_unite.json?client_id=32a76d168c65beff&category=综艺&genre=0&area=0&count=20&page=" . $i . "&headnum=1&tailnum=1");
            $datas = json_decode($by_keyword, 1);
            $arr = array();
            foreach ($datas['data'] as $k => $v) {
                if ($v['paid'] == 1) {
                    continue;
                }
                if (!$this->youku_url($v['programmeSite'][0]['episode'][0]['url'])) {
                    continue;
                }
                $arr[] = $v;
            }

            $ann = array();
            foreach ($arr as $k => $v) {
                $ann[$k]['name'] = $v['name'];
                $ann[$k]['programmeId'] = $v['programmeId'];
                $ann[$k]['genre'] = implode(',', $v['genre']);
                $ann[$k]['host'] = implode(',', $v['host']);
                $ann[$k]['vpic'] = $v['vpic'];
                $ann[$k]['brief'] = $v['brief'];
                $ann[$k]['subtitle'] = $v['subtitle'];
                $ann[$k]['releaseDate'] = $v['releaseDate'];
                foreach ($v['programmeSite'][0]['episode'] as $v2) {
                    $ann[$k]['programmeSite'][] = $v2['url'];
                };
            }
            //return $ann;

            $data = array();
            foreach ($ann as $k => $v) {
                $isvideo = Video::where('programmeId', $v['programmeId'])->first();
                if ($isvideo) {
                    continue;
                };
                $data['video_category_id'] = 3;
                $data['thumb'] = $v['vpic'];
                $data['published'] = trim($v['releaseDate']);
                $data['desc'] = trim($v['brief']);
                $data['programmeId'] = $v['programmeId'];
                $data['stars'] = $v['host'];
                $data['genre'] = $v['genre'];
                $data['title'] = $v['subtitle'];
                $data['name'] = $v['name'];
                $video = Video::create($data);
                foreach ($v['programmeSite'] as $link) {
                    $video->video_url()->create(['url' => $link]);
                }
            }
        }
        $this->attributes();
        return view('Admin.xHotel.video.youku_video')->with(['_video_add' => 'am-active', '_menu' => ''])->with('video_datas', $this->video_list());

    }

    public function onekey_video1()
    {
        $option_genre = array('1007', '1009', '1010', '1011', '1012', '1001', '1005', '1002', '1013', '1014', '1111');
        foreach ($option_genre as $option_g) {
            $by_keyword = $this->getJson("https://openapi.youku.com/v2/searches/show/top_unite.json?client_id=32a76d168c65beff&category=%E7%94%B5%E8%A7%86%E5%89%A7&genre=" . $option_g . "&area=0&headnum=2&tailnum=1");
            $datas = json_decode($by_keyword, 1);
            $arr = array();
            foreach ($datas['data'] as $k => $v) {
                if ($v['paid'] == 1) {
                    continue;
                }
                $arr[] = $v;
            }

            $ann = array();
            foreach ($arr as $k => $v) {
                if ($v['paid'] == 1) {
                    continue;
                };
                if ($this->youku_url($v['programmeSite'][0]['episode'][0]['url'])) {
                    $ann[$k]['name'] = $v['name'];
                    $ann[$k]['programmeId'] = $v['programmeId'];
                    $ann[$k]['name'] = $v['name'];
                    $ann[$k]['performer'] = $v['performer'][0];
                    $ann[$k]['vpic'] = $v['vpic'];
                    $ann[$k]['brief'] = $v['brief'];
                    $ann[$k]['subtitle'] = $v['subtitle'];
                    $ann[$k]['releaseDate'] = $v['releaseDate'];
                    $ann[$k]['programmeSite'] = $v['programmeSite'][0]['episode'][0]['url'];
                }
            }
            //return $ann;
            foreach ($ann as $k => $v) {
                $isvideo = Video::where('programmeId', $v['programmeId'])->first();
                if ($isvideo) {
                    continue;
                }
                $data['video_category_id'] = $this->sea_category('电视剧');
                $data['published'] = trim($v['releaseDate']);
                $data['desc'] = trim($v['brief']);
                $data['programmeId'] = $v['programmeId'];
                $data['stars'] = $v['performer'];
                $data['title'] = $v['subtitle'];
                $data['name'] = $v['name'];
                $data['thumb'] = $v['vpic'];
                $ann[$k]['data'] = $this->create_video($v['programmeSite']);
                if (empty($ann[$k]['data'])) {
                    continue;
                }
                $video = Video::create($data);
                foreach ($ann[$k]['data'] as $link) {
                    $video->video_url()->create(['url' => "http://v.youku.com/v_show/id_" . $link . "==.html"]);
                }
            }
        }
        $this->attributes();
        return view('Admin.xHotel.video.youku_video')->with(['_video_add' => 'am-active', '_menu' => ''])->with('video_datas', $this->video_list());

    }

    private function sea_category($str)
    {
        $cat = Category::where('name', $str)->first();
        $cat_c = Category::where('parent_id', $cat->id)->select('id')->get()->toArray();
        $arr = array();
        foreach ($cat_c as $v) {
            $arr[] = $v['id'];
        }
        return $arr[array_rand($arr)];
    }


    public function option_genre()
    {
        //$option = array('1007', '1009', '1010', '1011', '1012', '1001', '1005', '1002', '1013', '1014', '1111');
        $option = array('1007');
        return $option[array_rand($option)];
    }

    public function option_area()
    {
        //$option = array('1001', '1003', '1006', '1007', '1008', '1009', '1111');
        $option = array('1001');
        return $option[array_rand($option)];
    }

    public function getjson_api()
    {
        $by_keyword = $this->getJson("https://openapi.youku.com/v2/searches/show/top_unite.json?client_id=32a76d168c65beff&category=%E7%94%B5%E8%A7%86%E5%89%A7&genre=" . $this->option_genre() . "&area=" . $this->option_area() . "&headnum=2&tailnum=1");
        return json_decode($by_keyword, 1);
    }

    public function video_list()
    {
        $datas = $this->getjson_api();
        $arr = array();
        foreach ($datas['data'] as $k => $v) {
            if ($v['paid'] == 1) {
                continue;
            }
            $arr[] = $v;
        }
        $ann = array();
        foreach ($arr as $k => $v) {
            if ($v['paid'] == 1) {
                continue;
            };
            if ($this->youku_url($v['programmeSite'][0]['episode'][0]['url'])) {
                $ann[$k]['name'] = $v['name'];
                $ann[$k]['id'] = $v['programmeId'];
                $ann[$k]['performer'] = $v['performer'][0];
                //$ann[$k]['genre'] = $v['genre'][0];
                $ann[$k]['genre'] = "电视剧";
                $ann[$k]['published'] = $v['releaseDate'];
                $ann[$k]['thumb'] = $v['vpic'];
                $ann[$k]['desc'] = $v['brief'];
                $ann[$k]['score'] = $v['score'];
                $ann[$k]['subtitle'] = $v['subtitle'];
                $ann[$k]['releaseDate'] = $v['releaseDate'];
                $ann[$k]['url'] = $v['programmeSite'][0]['episode'][0]['url'];
            }
        }
        return $ann;
    }

    private function create_video($str)
    {
        //$lines = file_get_contents("compress.zlib://".$str);
        $ch = curl_init();
        //设置选项，包括URL
        curl_setopt($ch, CURLOPT_URL, $str);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        //执行并获取HTML文档内容
        $lines = curl_exec($ch);
        //释放curl句柄
        curl_close($ch);
        //打印获得的数据

        //dump($lines);
        $result = $this->pregURL($lines);
        //dump($result);

        if (!empty($result[1])) {
            return $result[1];
        } else {
            return '';
        }

    }


}
